
package com.joysuch.wwyt.bp.enums;

public enum DocTypes {

    // code 不超过5个字符
    DOC("doc", "文档"), VIDEO("video", "视频"), AUDIO("audio", "音频"), IMAGE("image", "图片");

    private String code;
    private String name;

    private DocTypes(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public boolean is(String code) {
        return code != null && this.code.equals(code);
    }

    public static DocTypes findByName(String name) {
        DocTypes[] values = DocTypes.values();
        for (DocTypes v : values) {
            if (v.getName().equals(name)) {
                return v;
            }
        }
        return null;
    }

    public static DocTypes findByCode(String code) {
        DocTypes[] values = DocTypes.values();
        for (DocTypes v : values) {
            if (v.getCode().equals(code)) {
                return v;
            }
        }
        return null;
    }

    public static String findNameByCode(String code) {
        DocTypes types = findByCode(code);
        return types == null ? null : types.name;
    }
}
